package spike.s003.sqlflow.entity;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * Created by ylyang on 04/04/2017.
 */
public class CourseEntity {
    private String courseID;
    private String courseName;
    private Date createTime;

    public String getCourseID() {
        return courseID;
    }

    public void setCourseID(String courseID) {
        this.courseID = courseID;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public static class BeanRowMapper implements RowMapper {
        private static final BeanPropertyRowMapper<CourseEntity> MAPPER = BeanPropertyRowMapper.newInstance(CourseEntity.class);

        public static CourseEntity mapRow(ResultSet rs) throws SQLException {
            CourseEntity courseEntity = MAPPER.mapRow(rs, rs.getRow());
            courseEntity.setCourseID(rs.getString("course_ID"));
            courseEntity.setCourseName(rs.getString("course_name"));
            courseEntity.setCreateTime(rs.getDate("create_time"));
            return courseEntity;
        }

        @Override
        public CourseEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
            return mapRow(rs);
        }
    }

    @Override
    public String toString() {
        return "CourseEntity{" +
                "courseID='" + courseID + '\'' +
                ", courseName='" + courseName + '\'' +
                ", createTime=" + createTime +
                '}';
    }
}
